package com.jxm.websocket.controller;

import com.jxm.websocket.pojo.Result;
import com.jxm.websocket.pojo.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
public class UserController {

    @RequestMapping("/login")
    public Result login(User user, HttpSession session){
        if (user.getPasswd()!=null&&user.getPasswd().equals("123")){
            session.setAttribute("user",user.getUserName());
        }else{
            return Result.error("密码错误,请重试");
        }
        return Result.success("登录成功");
    }

    @RequestMapping("/getUsername")
    public Result getUsername(HttpSession session){
        return Result.success((String) session.getAttribute("user"));
    }
}
